<template>
	<view>
		<view class="fx-center course-info">
			<image :src="cover_url" mode="aspectFill" class="course-img"></image>
			<view class="course-basic">
				<view class="title">{{courseName}}</view>
				<view style="margin: 8rpx 0 16rpx;">{{projectName}} ｜ {{state_name}}</view>
				<view class="">{{tip}}</view>
			</view>
		</view>
		<view class="course-step-box">
			<c-step :stepList="lessonArr" :pid="projectId"></c-step>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lessonArr: [],
				cover_url: '',
				courseName: '',
				projectName: '',
				state_name: '',
				tip: '',
				projectId: null,
				isFirst: true
			};
		},
		onLoad(e) {
			if (e.id) {
				this.projectId = e.id
				this.getCourse()
			}
		},
		onShow() {
			if (!this.isFirst) {
				this.getCourse()
			}
		},
		methods: {
			// 获取培训课程
			getCourse() {
				this.$api.requst(`/gwc/projects/${this.projectId}/course`, {
					id: this.projectId
				}).then((res) => {
					this.isFirst = false
					this.lessonArr = res.data.chapters
					this.tip = res.data.tip
					this.courseName = res.data.name
					this.projectName = res.data.project_name
					this.cover_url = res.data.cover_url
					this.state_name = res.data.state_name
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.course-info {
		background: #fff;
		color: #5C5F66;
		font-size: 26rpx;
		padding: 0 24rpx 34rpx;

		.course-img {
			width: 160rpx;
			height: 213rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-right: 32rpx;
			flex-shrink: 0;
		}

		.course-basic {
			flex: 1;

			.title {
				font-weight: bold;
				font-size: 40rpx;
				color: #161616;
			}
		}
	}

	.course-step-box {
		padding: 36rpx 32rpx;
	}
</style>